package org.xxpay.pay.channel.testpay;

import org.springframework.stereotype.Service;
import org.xxpay.core.common.domain.api.AbstractRes;
import org.xxpay.core.common.domain.api.ApiBuilder;
import org.xxpay.core.common.domain.api.PayRes;
import org.xxpay.core.common.domain.api.msg.QueryRetMsg;
import org.xxpay.core.common.util.MyLog;
import org.xxpay.core.entity.PayOrder;
import org.xxpay.pay.channel.BasePayment;

/**
 * @author: dingzhiwei
 * @date: 19/5/16
 * @description: 压力测试通道支付
 */
@Service
public class TestpayPaymentService extends BasePayment {

    private static final MyLog _log = MyLog.getLog(TestpayPaymentService.class);

    @Override
    public String getChannelName() {
        return TestpayConfig.CHANNEL_NAME;
    }

    /**
     * 支付
     * @param payOrder
     * @return
     */
    @Override
    public AbstractRes pay(PayOrder payOrder) {
        PayRes retObj = ApiBuilder.buildSuccess(PayRes.class);
        int updateCount = commonService.payOrderService.updateStatus4Ing(payOrder.getPayOrderId(), null);
        _log.info("[{}]更新订单状态为支付中:payOrderId={},result={}", getChannelName(), payOrder.getPayOrderId(), updateCount);
        retObj.setPayOrderId(payOrder.getPayOrderId());
        return retObj;
    }

    /**
     * 查询订单
     * @param payOrder
     * @return
     */
    @Override
    public QueryRetMsg query(PayOrder payOrder) {
       return QueryRetMsg.waiting();
    }
}
